package com.schoolcloud.serve.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.serve.entity.Spu;
import com.schoolcloud.serve.query.SpuQuery;
import com.schoolcloud.serve.service.SpuService;
import com.schoolcloud.serve.mapper.SpuMapper;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.stereotype.Service;

/**
* @author hongmizfb
* @description 针对表【spu】的数据库操作Service实现
* @createDate 2025-04-12 17:11:02
*/
@Service
public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu>
    implements SpuService{

    @Override
    public PageDTO<Spu> getSpuPage(SpuQuery query) {
        String categoryId = query.getCategoryId();
        String keyword = query.getKeyword();
        Page<Spu> page = lambdaQuery().eq(StrUtil.isNotBlank(categoryId), Spu::getCategoryId, categoryId)
                .like(StrUtil.isNotBlank(keyword), Spu::getSpuName, keyword)
                .page(query.toMpPage());
        return MpPageUtil.of(page, Spu.class);
    }
}




